<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%

String path = request.getContextPath();
	String BasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>


<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>川轻化健身房</title>
  <meta name="description" content="Ela Admin - HTML5 Admin Template">
    <meta name="viewport" content="width=device-width, initial-scale=1">



<link href="<%=BasePath%>/static/time/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<link rel="stylesheet" href="<%=BasePath%>/static/assets/css/normalize.css">
<link rel="stylesheet" href="<%=BasePath%>/static/assets/css/bootstrap.min.css">
<link rel="stylesheet" href="<%=BasePath%>/static/assets/css/font-awesome.min.css">
<link rel="stylesheet" href="<%=BasePath%>/static/assets/css/themify-icons.css">
<link rel="stylesheet" href="<%=BasePath%>/static/assets/css/style.css">
<link rel="stylesheet" href="<%=BasePath%>/static/vendor/bootstrap/css/bootstrap.css" />
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800' rel='stylesheet' type='text/css'>
<script type="text/javascript"
	src="<%=BasePath%>/static/vendor/jquery/jquery-1.10.2.min.js"></script>
<script type="text/javascript"
	src="<%=BasePath%>/static/vendor/bootstrap/js/bootstrap.min.js"></script>



</head>

<body>
<div class="modal fade" id="readerUpdateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h1 class="modal-title" align="center"><strong>会员续费</strong></h1>

                <form class="fh5co-form" id="defaultForm">

                    <h3 >会员ID</h3>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input type="text" name="memberID" class="form-control" id="memberID"  disabled="true" >

                        </div>
                    </div>

                    <h3 >会员名</h3>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input type="text" name="name" class="form-control" id="name" disabled="true">
                        </div>
                    </div>



                    <h3 >到期时间</h3>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input type="text" name="lasttime" class="form-control" id="lasttime" disabled="true">
                        </div>
                    </div>
                    <h3 >付费时长</h3>
                    <div class="form-group">
                        <label  class="btn btn-info">
                            <input type="radio"  name="gender"  id="option1" value="1">1月
                        </label>
                        <label  class="btn btn-info">
                            <input type="radio"  name="gender"  id="option2" value="2">2月
                        </label>
                        <label  class="btn btn-info">
                            <input type="radio"  name="gender"  id="option3"  value="3">3月
                        </label>
                        <label  class="btn btn-info">
                            <input type="radio"  name="gender"  id="option4"  value="6">6月
                        </label>
                        <label  class="btn btn-info">
                            <input type="radio"  name="gender"  id="option5" value="9">9月
                        </label>
                        <label  class="btn btn-info">
                            <input type="radio"  name="gender"  id="option6" value="10">10月
                        </label>
                        <label  class="btn btn-info">
                            <input type="radio"  name="gender"  id="option7"  value="12">12月
                        </label>
                    </div>

                </form>


                <button type="button" class="btn btn-warning btn-lg btn-block" id="validateBtn" name="validateBtn">付费</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="readmemcoa" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h1 class="modal-title" align="center"><strong>专属教练</strong></h1>

                <form class="fh5co-form" id="memcoaForm">

                    <h3 >会员ID</h3>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input type="text" name="memberID" class="form-control" id="memberID2"  disabled="true" >

                        </div>
                    </div>

                    <h3 >会员名</h3>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input type="text" name="name" class="form-control" id="name2" disabled="true">
                        </div>
                    </div>
                    <h3 >教练ID</h3>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input type="text" name="coachID" class="form-control" id="coachID" disabled="true">
                        </div>
                    </div>
                    <h3 >教练姓名</h3>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input type="text" name="coachname" class="form-control" id="coachname" disabled="true">
                        </div>
                    </div>

                </form>


                <button type="button" class="btn btn-warning btn-lg btn-block" id="unbind" name="validateBtn">解除绑定</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="bindmemcoa" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h1 class="modal-title" align="center"><strong>绑定专属教练</strong></h1>

                <form class="fh5co-form" id="bindmemcoaForm">

                    <h3 >会员ID</h3>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input type="text" name="memberID" class="form-control" id="memberID3"  disabled="true" >

                        </div>
                    </div>

                    <h3 >会员名</h3>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input type="text" name="name" class="form-control" id="name3" disabled="true">
                        </div>
                    </div>
                    <h3 >教练ID</h3>
                    <div class="form-group">
                        <div class="input-group">
                            <div class="input-group-addon"><i class="fa fa-user"></i></div>
                            <input type="text" name="coachID" class="form-control" id="coachID3" >
                        </div>
                    </div>
                </form>


                <button type="button" class="btn btn-warning btn-lg btn-block" id="bind" name="validateBtn">绑定</button>
            </div>
        </div>
    </div>
</div>


	<!-- Left Panel -->
	    <!-- Left Panel -->
    <aside id="left-panel" class="left-panel">
        <nav class="navbar ">
            <div id="main-menu" class="main-menu ">
                <ul class="nav navbar-nav">
                    <li class="menu-item "><a href="../admin/index" class="dropdown-toggle"><i
                            class="menu-icon fa fa-home"></i>主页</a></li>
                    <li class="menu-title">会员管理</li>
                    <!-- /.menu-title -->
                    <li class="menu-item active"><a href="../admin/member"
                                              class="dropdown-toggle"> <i class="menu-icon  fa fa-search"></i>查看会员信息
                    </a></li>

                    <li class="menu-title">教练管理</li>
                    <!-- /.menu-title -->
                    <li class="menu-item "><a href="../admin/coachs"
                                                    class="dropdown-toggle"> <i class="menu-icon fa   fa-users"></i>查看教练信息
                    </a></li>
                    <li class="menu-item"><a href="../admin/addcoach"
                                             class="dropdown-toggle"> <i
                            class="menu-icon fa  fa-cut (alias)"></i>激活教练账号
                    </a></li>
                    <li class="menu-title">公告信息管理</li>
                    <li class="menu-item"><a href="../admin/notice"
                                             class="dropdown-toggle"> <i
                            class="menu-icon fa    fa-location-arrow"></i>查看公告信息
                    </a></li>
                    <li class="menu-item"><a href="../admin/addnotice"
                                             class="dropdown-toggle"> <i class="menu-icon fa    fa-align-justify"></i>添加公告信息
                    </a></li>


                </ul>
            </div><!-- /.navbar-collapse -->
        </nav>
    </aside>
    <!-- /#left-panel -->
    <!-- Right Panel -->
    <div id="right-panel" class="right-panel">
        <!-- Header-->
        <header id="header" class="header">
            <div class="top-left">
              <div class="navbar-header">
                   <a class="navbar-brand" href="./"><p style="font-size:30px" >健身房后台管理</p></a>

                   <a id="menuToggle" class="menutoggle"><h4><i class="fa fa-bars fa-lg"></i></h4></a>
                </div>
            </div>
            <div class="top-right">
                <div class="header-menu">
                <div class="header-left">

					</div>
                    <div div class="user-area dropdown float-right">	
                   <span class="text-success"> <%HttpSession name = request.getSession(); %>
                                            <%=name.getAttribute("adminname") %>欢迎你！</span>
                    </div>


                </div>
            </div>
        </header>
        <div class="content">

            <div class="animated fadeIn">
                <div class="card">
                    <h1 class="text-center">会员信息管理</h1>
                    <div class="col-md-12">


                        <div class="card-body">
                            <table class="table table-striped table-bordered dateTable no-footer" id="reader_table">
                                <thead>
                                <tr >
                                    <th><h3 align="center">用户id</h3></th>
                                    <th><h3 align="center">用户名</h3></th>
                                    <th><h3 align="center">手机号</h3></th>
                                    <th><h3 align="center">加入时间</h3></th>
                                    <th><h3 align="center">付费类型</h3></th>
                                    <th><h3 align="center">到期时间</h3></th>
                                    <th><h3  class="text-warning" align="center">操作</h3></th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>

                        </div>
                    </div>
                    <div class="row">
                        <!--分页文字信息  -->
                        <div class="col-md-6" ><p class="lend" id="page_info_area" class="text-success"></p></div>
                        <!-- 分页条信息 -->
                        <div class="col-md-6" i><h2 class="lend" id="page_nav_area"></h2></div>
                    </div>


                </div>
            </div>
         </div>

        </div>
	</div>

    <script src="<%=BasePath%>/static/assets/js/vendor/jquery-2.1.4.min.js"></script>
    <script src="<%=BasePath%>/static/assets/js/popper.min.js"></script>
    <script src="<%=BasePath%>/static/assets/js/bootstrap.min.js"></script>
    <script src="<%=BasePath%>/static/assets/js/jquery.matchHeight.min.js"></script>
    <script src="<%=BasePath%>/static/assets/js/main.js"></script>
    <script type="text/javascript" src="<%=BasePath%>/static/time/jquery/jquery-1.8.3.min.js" charset="UTF-8"></script>
<script type="text/javascript" src="<%=BasePath%>/static/time/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=BasePath%>/static/time/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
<script type="text/javascript" src="<%=BasePath%>/static/time/js/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
    $(function () {
        $.ajax({
            url:"../admin/readUser",
            type:"GET",
            success:function (data) {
                build_table(data.data);
            }

        });
    });
    function build_table(data) {
        $("#reader_table tbody").empty();
        $.each(data,function (i,member) {
            var readUid = $("<td></td>").addClass("classUid").append(member.uid);
            var readNickname = $("<td></td>").addClass("classNickname").append(member.nickname);
            var readPhone = $("<td></td>").addClass("classPhone").append(member.phone);
            var readJointime = $("<td></td>").addClass("classJointime").append(member.jointime);
            var readLevel = $("<td></td>").addClass("classLevel").append(member.level);
            var readLasttime = $("<td></td>").addClass("classLasttime").append(member.lasttime);
            var editBtn = $("<button></button>").addClass("btn btn-success btn-lg edit_btn")
                .append($("<span></span>").addClass("glyphicon glyphicon-pencil")).append("续费");


            var delBtn =  $("<button></button>").addClass("btn btn-Warning btn-lg delete_btn")
                .append($("<span></span>").addClass("glyphicon glyphicon-user")).append("专属教练");

            var btnTd = $("<td></td>").append(editBtn).append(" ").append(delBtn);

            $("<tr align='center'></tr>")
                .append(readUid)
                .append(readNickname)
                .append(readPhone)
                .append(readJointime)
                .append(readLevel)
                .append(readLasttime)
                .append(btnTd)
                .appendTo("#reader_table tbody");
        });
    }
    $(document).on("click",".edit_btn",function () {
        var id = $(this).parents("tr").children("td:nth-child(1)").text();
        var nickname = $(this).parents("tr").children("td:nth-child(2)").text();
        var lasttime = $(this).parents("tr").children("td:nth-child(6)").text();
        $("#memberID").val(id);
        $("#name").val(nickname);
        $("#lasttime").val(lasttime);
        $("#readerUpdateModal").modal({
            backdrop:"static"
        });
    });
    $(document).on("click",".delete_btn",function () {
        var uid = $(this).parents("tr").children("td:nth-child(1)").text();
        var name = $(this).parents("tr").children("td:nth-child(2)").text();
        $.ajax({
            url:"../admin/readMemcoa",
            data:{
                uid:uid
            },
            type:"post",
            success:function (data) {
                var memcoach = data.data;
                if(data.msg == "success"){
                    if(memcoach == null){
                        $("#memberID3").val(uid);
                        $("#name3").val(name);
                        $("#bindmemcoa").modal({
                            backdrop:"static"
                        });

                    }else{
                        $("#memberID2").val(uid);
                        $("#name2").val(name);
                        $("#coachID").val(memcoach.cid);
                        $("#coachname").val(memcoach.name);
                        $.ajax({
                            url:"../admin/"
                        })
                        $("#readmemcoa").modal({
                            backdrop:"static"
                        });
                    }
                }
            }
        })


    });
    $(document).ready(function () {
        $("#validateBtn").click(function(){
            var memberID = $("#memberID").val();
            var gender=$("input[name='gender']:checked").val();
            if(gender==""||gender==null){
                alert("请选择相应的月份");
                return;
            }
           $.ajax({
               url:"../admin/upLevelById",
               data:{
                   uid:memberID,
                   month:gender
               },
               type:"post",
               success:function (data) {
                   if(data.msg=="success"){
                       $("#lasttime").val(data.data);
                       alert("充值成功，到期时间为："+data.data);
                       window.location.reload();
                   }
               }
           })

        });
        $("#bind").click(function () {
            var uid = $("#memberID3").val();
            var cid = $("#coachID3").val();
            if(cid==null||cid==""){
                alert("教练ID不能为空");
                return;
            }
            $.ajax({
                url:"../admin/bindcoach",
                data:{
                    uid:uid,
                    cid:cid
                },
                type:"GET",
                success:function (data) {
                    if(data.msg=="success"){
                        alert("绑定成功");
                        $("#bindmemcoa").modal("hide");
                    }
                }
            });
        });
        $("#unbind").click(function () {
            var uid = $("#memberID2").val();
            var cid = $("#coachID").val();
            $.ajax({
                url:"../admin/unbindcoach",
                data:{
                    uid:uid,
                    cid:cid
                },
                type:"GET",
                success:function (data) {
                    if(data.msg=="success"){
                        alert("解绑成功");
                        $("#readmemcoa").modal("hide");
                    }
                }
            });
        });
    })
</script>

</body>
</html>
